Python Project Online Quiz System
The Online Quiz System is a simple Python project
that allows users to answer multiple-choice questions through the command line.
The program checks each answer automatically, calculates the score, finds the
percentage, assigns a grade, and displays the final result. It also gives the
user the option to play the quiz again without restarting the program.
This project is useful for beginners because it combines
many basic Python concepts into one practical application.
Project Features
1. User Login (Name Input)
The program first asks the user to enter their name. This
name is displayed in the final result to make the quiz more personal.
2. Multiple Choice Questions
The quiz contains several questions, and each question has
four options (A, B, C, and D). The user selects the correct answer by typing
the option letter.
3. Automatic Answer Checking
After the user enters an answer, Python compares it with the
correct answer stored in the program. If the answer matches, the score
increases automatically. Otherwise, the correct answer is displayed.
4. Score Calculation
Every correct answer earns one mark. At the end of the quiz,
the program counts the total number of correct and incorrect answers.
5. Percentage Calculation
The program calculates the percentage using this formula:
Percentage = (Correct Answers ÷ Total Questions) × 100
This helps students understand their overall performance.
6. Grade System
Based on the percentage, the program assigns a grade.
- 90%
and above – A+
- 80%
to 89% – A
- 70%
to 79% – B
- 60%
to 69% – C
- 50%
to 59% – D
- Below
50% – Fail
7. Final Result
Once all questions are completed, the program displays:
- Student
Name
- Total
Questions
- Correct
Answers
- Wrong
Answers
- Percentage
- Grade
- Pass
or Fail Status
This gives the user a complete summary of their performance.
Python While loop programs
8. Play Again Option
After showing the result, the program asks whether the user
wants to play again. If the user enters Y, the quiz starts again. If the
user enters N, the program ends with a thank-you message.
Python Online Quiz System Project
# ==========================================
# ONLINE QUIZ SYSTEM USING PYTHON
# ==========================================
questions = [
{
"question": "1. What is Python?",
"options": [
"A. Programming Language",
"B. Database",
"C. Operating System",
"D. Browser"
],
"answer": "A"
},
{
"question": "2. Which keyword is used to create a function?",
"options": [
"A. function",
"B. define",
"C. def",
"D. func"
],
"answer": "C"
},
{
"question": "3. Which loop is used when the number of iterations is known?",
"options": [
"A. while",
"B. for",
"C. do while",
"D. repeat"
],
"answer": "B"
},
{
"question": "4. Which data type stores multiple values?",
"options": [
"A. int",
"B. float",
"C. list",
"D. bool"
],
"answer": "C"
},
{
"question": "5. Which symbol is used for comments in Python?",
"options": [
"A. //",
"B. <!-- -->",
"C. #",
"D. **"
],
"answer": "C"
}
]
# ================================
# Function to Run Quiz
# ================================
def start_quiz():
score = 0
print("\n" + "=" * 50)
print(" ONLINE QUIZ SYSTEM")
print("=" * 50)
name = input("Enter Your Name: ")
print("\nWelcome,", name)
print("Choose the correct option (A/B/C/D)")
print("-" * 50)
question_number = 1
for q in questions:
print("\nQuestion", question_number)
print(q["question"])
for option in q["options"]:
print(option)
answer = input("Your Answer: ").upper()
while answer not in ["A", "B", "C", "D"]:
print("Invalid Choice! Enter A, B, C or D.")
answer = input("Your Answer: ").upper()
if answer == q["answer"]:
print("Correct Answer")
score += 1
else:
print("Wrong Answer")
print("Correct Answer:", q["answer"])
question_number += 1
total = len(questions)
wrong = total - score
percentage = (score / total) * 100
if percentage >= 90:
grade = "A+"
elif percentage >= 80:
grade = "A"
elif percentage >= 70:
grade = "B"
elif percentage >= 60:
grade = "C"
elif percentage >= 50:
grade = "D"
else:
grade = "Fail"
print("\n" + "=" * 50)
print(" FINAL RESULT")
print("=" * 50)
print("Student Name :", name)
print("Total Questions :", total)
print("Correct Answers :", score)
print("Wrong Answers :", wrong)
print("Percentage : {:.2f}%".format(percentage))
print("Grade :", grade)
if grade == "Fail":
print("Status : Better Luck Next Time!")
else:
print("Status : Congratulations! You Passed.")
print("=" * 50)
# ================================
# Main Program
# ================================
while True:
start_quiz()
choice = input("\nDo you want to play again? (Y/N): ").upper()
if choice != "Y":
print("\nThank you for using the Online Quiz System.")
print("Have a Great Day!")
break
Output:
Conclusion
The Python Online Quiz System is an excellent
beginner project for students. It teaches how to collect user input, work with
questions and answers, calculate scores and percentages, apply grading logic,
and control program flow using loops and conditions. By building this project,
students gain practical experience with the core concepts of Python programming
while creating a useful and interactive application.
Comments
Post a Comment